package nix.jdbc;

import java.beans.PropertyVetoException;
import java.sql.Connection;
import java.sql.SQLException;

import org.junit.Test;

import com.mchange.v2.c3p0.ComboPooledDataSource;

public class Test4 {

	/**
	 * 代码配置（会覆盖配置文件配置）
	 * @throws PropertyVetoException
	 * @throws SQLException
	 */
	@Test
	public void fun1() throws PropertyVetoException, SQLException {

		ComboPooledDataSource dataSource = new ComboPooledDataSource();
		dataSource.setDriverClass("com.mysql.jdbc.Driver");
		dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/test");
		dataSource.setUser("root");
		dataSource.setPassword("race");
		
		dataSource.setAcquireIncrement(5);
		dataSource.setInitialPoolSize(20);
		dataSource.setMaxPoolSize(50);
		dataSource.setMinPoolSize(2);
		
		Connection con = dataSource.getConnection();
		System.out.println(con);
		con.close();
	}
	
	/**
	 * 配置文件配置（默认配置）
	 * @throws SQLException 
	 */
	@Test
	public void fun2() throws SQLException {
		
		ComboPooledDataSource dataSource = new ComboPooledDataSource();
		Connection con = dataSource.getConnection();
		System.out.println(con);
		con.close();
	}
	
	/**
	 * 配置文件配置（命名配置）
	 * @throws SQLException 
	 */
	@Test
	public void fun3() throws SQLException {
		
		ComboPooledDataSource dataSource = new ComboPooledDataSource("oracle-config");
		Connection con = dataSource.getConnection();
		System.out.println(con);
		con.close();
	}
}
